<template>
  <yd-tab>
    <yd-tab-panel label="已完成">
      <yd-infinitescroll
        :distance="20"
        :callback="get_orgainize_finish_orders"
        ref="orgainize_finish_orders"
      >
        <div class="onlist" slot="list">
          <team-result
            :organizes="item"
            v-for="(item, index) in orgainize_finish_orders.order_list"
            :key="index"
          ></team-result>
        </div>
        <span slot="doneTip">没有更多了</span>
      </yd-infinitescroll>
    </yd-tab-panel>
    <yd-tab-panel label="待消费">
      <yd-infinitescroll
        :distance="20"
        :callback="get_organize_consumed_orders"
        ref="organize_consumed_orders"
      >
        <div class="onlist" slot="list">
          <team-result
            :organizes="item"
            v-for="(item, index) in organize_consumed_orders.order_list"
            :key="index"
          ></team-result>
        </div>
        <span slot="doneTip">没有更多了</span>
      </yd-infinitescroll>
    </yd-tab-panel>
    <yd-tab-panel label="待付款">
      <yd-infinitescroll
        :distance="20"
        :callback="get_organize_to_bo_paid_orders"
        ref="organize_to_bo_paid_orders"
      >
        <div class="onlist" slot="list">
          <team-result
            :organizes="item"
            v-for="(item, index) in organize_to_bo_paid_orders.order_list"
            :key="index"
          ></team-result>
        </div>
        <span slot="doneTip">没有更多了</span>
      </yd-infinitescroll>
    </yd-tab-panel>
  </yd-tab>
</template>
<script>
import teamResult from "@/components/organize_team/team_result";

export default {
  name: "test",
  data() {
    return {
      page_index: 1,
      page_size: 10,
      // 已完成的订单
      orgainize_finish_orders: {
        page_index: 1,
        order_list: []
      },
      // 待消费的订单
      organize_consumed_orders: {
        page_index: 1,
        order_list: []
      },
      // 待支付的订单
      organize_to_bo_paid_orders: {
        page_index: 1,
        order_list: []
      }
    };
  },
  components: {
    teamResult
  },
  mounted() {
	  this.get_orgainize_finish_orders()
	  this.get_organize_consumed_orders()
	  this.get_organize_to_bo_paid_orders()
  },
  methods: {
    /*
     * 获取组队完成的订单
     * 作者：gzt
     * 时间：2019-11-30 17:17:34
     */
    get_orgainize_finish_orders() {
      let _this = this;
      this.$post(this.$api.organizeteam.organize_team_order, {
        pageNum: this.page_index,
        pageSize: this.page_size,
        request: {
          orderStatus: "COMPLETED"
        }
      }).then(res => {
        if (res.success) {
          _this.orgainize_finish_orders.order_list = [
            ..._this.orgainize_finish_orders.order_list,
            ...res.data.result
          ];
          if (res.data && res.data.result.length < _this.page_size) {
            /* 所有数据加载完毕 */
            this.$refs.orgainize_finish_orders.$emit(
              "ydui.infinitescroll.loadedDone"
            );
            return;
          }
          /* 单次请求数据完毕 */
          this.$refs.orgainize_finish_orders.$emit(
            "ydui.infinitescroll.finishLoad"
          );
          this.orgainize_finish_orders.page_index++;
        }
      });
    },

    /*
     * 待消费的订单
     * 作者：gzt
     * 时间：2019-11-30 17:24:45
     */
    get_organize_consumed_orders() {
      let _this = this;
      this.$post(this.$api.organizeteam.organize_team_order, {
        pageNum: this.page_index,
        pageSize: this.page_size,
        request: {
          orderStatus: "WAIT_CONSUM"
        }
      }).then(res => {
        if (res.success) {
          console.log(res)
          _this.organize_consumed_orders.order_list = [
            ..._this.organize_consumed_orders.order_list,
            ...res.data.result
          ];
          if (res.data && res.data.result.length < _this.page_size) {
            /* 所有数据加载完毕 */
            this.$refs.organize_consumed_orders.$emit(
              "ydui.infinitescroll.loadedDone"
            );
            return;
          }
          /* 单次请求数据完毕 */
          this.$refs.organize_consumed_orders.$emit(
            "ydui.infinitescroll.finishLoad"
          );
          this.organize_consumed_orders.page_index++;
        }
      });
    },

    /*
     * 待支付的订单
     * 作者：gzt
     * 时间：2019-11-30 17:28:41
     */
    get_organize_to_bo_paid_orders() {
      let _this = this;
      this.$post(this.$api.organizeteam.organize_team_order, {
        pageNum: this.page_index,
        pageSize: this.page_size,
        request: {
          orderStatus: "WAIT_PAY"
        }
      }).then(res => {
        if (res.success) {
          _this.organize_to_bo_paid_orders.order_list = [
            ..._this.organize_to_bo_paid_orders.order_list,
            ...res.data.result
          ];
          if (res.data && res.data.result.length < _this.page_size) {
            /* 所有数据加载完毕 */
            this.$refs.organize_to_bo_paid_orders.$emit(
              "ydui.infinitescroll.loadedDone"
            );
            return;
          }
          /* 单次请求数据完毕 */
          this.$refs.organize_to_bo_paid_orders.$emit(
            "ydui.infinitescroll.finishLoad"
          );
          this.organize_to_bo_paid_orders.page_index++;
        }
      });
    }
  }
};
</script>
<style scoped>
.zd {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 0.3rem;
  font-size: 0.3rem;
}

.zd span {
  text-decoration: blink;
  color: rgb(226, 103, 21);
}

.zd img {
  height: 0.4rem;
  padding-right: 0.1rem;
}

.onlist {
  padding: 0.3rem;
}
</style>
